﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rotempco.Core.Logic
{
    public class LookupLogic
    {
        public static List<TReturnValue> GetList<TReturnValue, TKey, TLookupValue>(ILookup<TKey, TLookupValue> instance, List<TKey> valueList, Func<TLookupValue, TReturnValue> selector, bool distinct = false)
        {
            List<TReturnValue> tReturnValue = new List<TReturnValue>();
            foreach (TKey key in valueList)
            {
                if (instance.Contains(key))
                    tReturnValue.AddRange(instance[key].Select(selector));
            }

            if (distinct)
                return tReturnValue.Distinct().ToList();

            return tReturnValue;
        }
    }
}
